package com.hunan.api.catv.action.search;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.search.SearchBiz;
import com.hunan.api.catv.utils.sensitivewords.SensitivewordFilterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(Api.search)
@Validated
public class SearchAction extends BaseAction {


    @Autowired
    SearchBiz searchBiz;

    /**
     * 首页精选列表
     *
     * @param key
     * @return
     */
    @GetMapping("/list")
    public Result list(String key, Integer pageNum, HttpServletRequest request) {
        boolean isKeyWord = SensitivewordFilterUtil.contains(key);
        if (isKeyWord) {
            return buildFail(null, "暂无相关内容");
        }
        return buildOK(searchBiz.list(key, pageNum, getPageSize(request)), "");
    }

    @GetMapping("/init")
    public Result init() {
        return buildOK(searchBiz.init(), "");
    }
}